
$(function() {
	/** 开始部署按钮点击*/
	$('#start-deploy').click(function() {
		// input 赋值name
		var dests = $('#dest-server').children();
		for(var i = 1; i < dests.length;i++) {
			var dest = dests[i];
			var inputs = $(dest).find('input');
			// 配置文件下标
			var index = -1;
			for(var j = 0;j < inputs.length;j++) {
				var inputbox = $(inputs[j]);
				
				switch(j)
				{
					case 0:
						inputbox.attr('name','hostVO.dests['+(i-1)+'].hostIp');
						break;
					case 1:
						inputbox.attr('name','hostVO.dests['+(i-1)+'].port');
						break;
					case 2:
						inputbox.attr('name','hostVO.dests['+(i-1)+'].userName');
						break;
					case 3:
						inputbox.attr('name','hostVO.dests['+(i-1)+'].passWord');
						break;
					case 4:
						inputbox.attr('name','hostVO.dests['+(i-1)+'].webappPath');
						break;
					case 5:
						inputbox.attr('name','hostVO.dests['+(i-1)+'].startUpPath');
						break;
					case 6:
						inputbox.attr('name','hostVO.dests['+(i-1)+'].shutDownPath');
						break;
					default:
						if(inputbox.attr('class') == 'warpath') {
							// 文件 war路径
							index++;
							inputbox.attr('name','hostVO.dests['+(i-1)+'].cfgs['+index+'].warDir');
							
						} else if(inputbox.attr('class') == 'file') {
							// 文件input
							inputbox.attr('name','hostVO.dests['+(i-1)+'].cfgs['+index+'].file');
							
						}
				}
			}
			
		}
		// 提交表单
		var deployForm = $('#deploy-form');
		deployForm.attr('action','deploy.do');
		deployForm.submit();
		
	});
	
	/** 通过配置文件部署*/
	$('#start-deploy-cfg').click(function() {
		var deployForm = $('#deploy-form');
		deployForm.attr('action','deployWithFile.do');
		deployForm.submit();
	});
	
	/** ws消息推送*/
	
});

/** 添加配置文件*/
function addCfgFile(btn) {
	var button = $(btn);
	var fileHtml = button.parent().prev().html();
	button.parent().prev().before(fileHtml);
}

/** 添加一台分发服务器*/
function addDestServer(dest) {
	var button = $(dest);
	var dests = button.parent().prev();
	var nodeHtml = dests.children().eq(0).html();
	dests.append(nodeHtml);
}
/** 删除配置文件*/
function deleteCfgFile(btn) {
	$(btn).parent().parent().remove();
}
/** 删除分发服务器*/
function deleteDestServer(btn) {
	$(btn).parent().remove();
}
